package ld;

import ld.utils.MysqlUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * Created by David on 2017/7/30 030.
 */
@WebServlet(name = "TestServlet")
public class TestServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("1111");

        try {
            ResultSet ret = MysqlUtils.querySql("select * from user");
            PrintWriter out = response.getWriter();
            while (ret.next()){
                for (int i = 1; i <= 4; i++) {
                    out.println(i + ": " + ret.getString(i));
                }
                out.println();
            }
            ret.close();
            //MysqlUtils.conn.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
